home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: CShell
- ** File: utils.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "CShell.h" /* Get the CShell includes/typedefs, etc. */
- #include "CShellCommon.h" /* Get the stuff in common with rez. */
- #include "CShell.protos" /* Get the prototypes for CShell. */
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- #define BASE 10
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void appendi2cstr(char *cstr, short i)
- {
- i2cstr(cstr + strlen(cstr), i);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- short appendi2pstr(char *pstr, short i)
- {
- short j;
-
- j = 0;
- if (i >= BASE) j = appendi2pstr(pstr, i / BASE);
- pstr[++*pstr] = "0123456789ABCDEF"[i - j];
- return(BASE * i);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- short i2cstr(char *cstr, short i)
- {
- short j;
-
- cstr[1] = j = 0;
- if (i >= BASE)
- j = i2cstr(cstr + 1, i / BASE);
- *cstr = "0123456789ABCDEF"[i - j];
- return(BASE * i);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void i2pstr(char *pstr, short i)
- {
- *pstr = 0;
- appendi2pstr(pstr, i);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void pstrcat(char *d, char *s)
- {
- short i;
-
- for (i = 0; i < s[0];)
- d[++d[0]] = s[++i];
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void pstrcpy(char *d, char *s)
- {
- short i;
-
- i = *s;
- do {
- d[i] = s[i];
- } while (i--);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- short GetHexByte(char *cptr)
- {
- short val, i, chr;
-
- for (val = 0, i = 0; i < 2; ++i) {
- chr = cptr[i];
- if (chr == '=') return(cptr[++i]);
- if (chr > 'F') chr -= 0x20;
- if (chr > '9') chr -= ('A' - '9' - 1);
- val = (val << 4) + chr - '0';
- }
- return(val);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This code expects the key equivalents to be in item #2, which is a StatText
- ** item that is located so the text is outside of the dialog. This allows us
- ** to put key equivalent information in the resource fork, so the key
- ** equivalents are localizable. */
-
- #pragma segment Main
- pascal Boolean keyEquivFilter(DialogPtr dlg, EventRecord *event, short *item)
- {
- short itemType;
- Handle itemHndl;
- Rect itemRect;
- Str255 itemText;
- short i, theChr, theMod, equivChr, modMask, modVal, itemNum;
- long tick;
-
- if (event->what == updateEvt) {
- if (dlg == (DialogPtr)event->message) OutlineDialogItem(dlg, 1);
- return(false);
- }
-
- if (event->what != keyDown) return(false);
-
- itemNum = 0;
-
- theChr = event->message & charCodeMask;
- theMod = event->modifiers & keyCodeMask;
-
- if ((theChr == 0x0D) || (theChr == 0x03)) { /* If return or enter... */
- if (!(theMod & (cmdKey + optionKey + controlKey))) itemNum = 1;
- }
- else {
-
- GetDItem(dlg, 2, &itemType, &itemHndl, &itemRect);
- GetIText(itemHndl, itemText);
-
- for (i = 1; i <= *itemText; i += 9) {
- equivChr = GetHexByte((char *) itemText + i);
- modMask = GetHexByte((char *) itemText + i + 2) << 8;
- modVal = GetHexByte((char *) itemText + i + 4) << 8;
- itemNum = GetHexByte((char *) itemText + i + 6);
- if (theChr == equivChr)
- if ((theMod & modMask) == modVal) break;
- itemNum = 0;
- }
- }
-
- if (itemNum) {
- GetDItem(dlg, itemNum, &itemType, &itemHndl, &itemRect);
- HiliteControl((ControlHandle)itemHndl, 1);
- tick = TickCount();
- while (TickCount() < tick + 10);
- HiliteControl((ControlHandle)itemHndl, 0);
- *item = itemNum;
- return(true);
- }
-
- return(false);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void OffsetControl(ControlHandle ctl, short dx, short dy)
- {
- Rect ctlRect;
-
- ctlRect = (*ctl)->contrlRect;
- MoveControl(ctl, ctlRect.left + dx, ctlRect.top + dy);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void DoDrawGrowIcon(WindowPtr window, Boolean horLine, Boolean verLine)
- {
- WindowPtr oldPort;
- Rect rct;
- RgnHandle oldClip, newClip;
-
- GetPort(&oldPort);
- SetPort(window);
-
- rct = window->portRect;
- rct.left = rct.right - 15;
- rct.top = rct.bottom - 15;
-
- if (window != FrontWindow()) {
- FrameRect(&rct);
- ++rct.top;
- ++rct.left;
- EraseRect(&rct);
- SetPort(oldPort);
- return;
- }
-
- oldClip = NewRgn();
- newClip = NewRgn();
-
- if (horLine) rct.left = window->portRect.left;
- if (verLine) rct.top = window->portRect.top;
- RectRgn(newClip, &rct);
-
- GetClip(oldClip);
- SetClip(newClip);
- DrawGrowIcon(window); /* Draw grow icon without scrollbar lines. */
-
- SetClip(oldClip);
- DisposeRgn(oldClip);
- DisposeRgn(newClip);
-
- SetPort(oldPort);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void DoDrawControls(WindowPtr window, Boolean scrollBarsOnly)
- {
- ControlHandle ctl;
-
- ctl = ((WindowPeek)window)->controlList;
- while (ctl) {
- DoDraw1Control(ctl, scrollBarsOnly);
- ctl = (*ctl)->nextControl;
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void DoDraw1Control(ControlHandle ctl, Boolean scrollBarsOnly)
- {
- Boolean front;
- WindowPtr window, oldPort;
- Rect rct;
- ControlHandle scrollCtl;
- static Handle scrollProc;
-
- front = ((window = (*ctl)->contrlOwner) == FrontWindow());
-
- if (!scrollProc) {
- SetRect(&rct, 0, 0, 16, 100);
- scrollCtl = NewControl(window, &rct, nil, false, 0, 0, 0, scrollBarProc, 0);
- if (scrollCtl) {
- scrollProc = (*scrollCtl)->contrlDefProc;
- DisposeControl(scrollCtl);
- }
- }
-
- if ((*ctl)->contrlDefProc == scrollProc) {
- if (front) Draw1Control(ctl);
- else {
- GetPort(&oldPort);
- SetPort(window);
- rct = (*ctl)->contrlRect;
- FrameRect(&rct);
- InsetRect(&rct, 1, 1);
- EraseRect(&rct);
- SetPort(oldPort);
- }
- }
- else if (!scrollBarsOnly) Draw1Control(ctl);
- }
-
-
-
-